package com.atguigu.guli.service.controller;

import com.atguigu.guli.service.result.R;
import com.atguigu.guli.service.service.MediaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;

@RestController

@RequestMapping("/vod/media")
public class AdminMedicaController {
    @Autowired
    MediaService mediaService;

    @PostMapping("/upload")  //上传文件
    public R upload(MultipartFile file){

         String videoId = mediaService.upload(file);
         return R.ok().data("id",videoId);
    }

    //获取播放地址
    @GetMapping("/getUrl/{vid}")
    public  R getUrl(@PathVariable String vid){
         String url = mediaService.getUrl(vid);
         return R.ok().data("url",url);
    }

    //获取播放凭证
    @GetMapping("/getAuth/{vid}")
    public R getAuth(@PathVariable String vid){
        String auth = mediaService.getAuth(vid);
        return R.ok().data("auth",auth);
    }
}
